﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace MainZNQD
{
    public class Solution
    {
        public List<Action> Actions = new List<Action>();
        public List<Activity> Activities = new List<Activity>();
        public string File { get; set; }
        public string ID { get; set; }
        public string Name { get; set; }
        public string ChinaName { get; set; }
        public void LoadXml(XmlDocument doc) 
        {
            XmlNode root = doc.DocumentElement;
            XmlAttribute attr = root.Attributes["ID"];
            if (attr!=null) 
            {
                this.ID = attr.Value;
            }
            attr = root.Attributes["Name"];
            if (attr != null) 
            {
                this.Name = attr.Value;
            }
            attr=root.Attributes["ChinaName"];
            if (attr != null) 
            {
                this.ChinaName = attr.Value;
            }
            foreach (XmlNode item in root.ChildNodes)
            {
                if (item.Name == "Actions") 
                {
                    LoadActions(item);
                }
                else if (item.Name == "Activities") 
                {
                    LoadActivities(item);
                }
                else if (item.Name == "File") 
                {
                    attr = item.Attributes["Url"];
                    this.File = attr.Value;
                }   
            }
        }

        private void LoadActivities(XmlNode node)
        {
            foreach (XmlNode item in node.ChildNodes)
            {
                Activity action = new Activity();
                action.LoadXml(item);
                this.Activities.Add(action);
            }
        }

        private void LoadActions(XmlNode node)
        {
            foreach (XmlNode item in node.ChildNodes)
            {
                Action action = new Action();
                action.LoadXml(item);
                this.Actions.Add(action);
            }
        }
    }
}
